<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .father {
            width: 500px;
            height: 500px;
            background-color: blue;
        }

        .son {
            width: 300px;
            height: 300px;
            background-color: rgb(221, 0, 0);
        }
    </style>
</head>

<body>
    <div class="father">
        <div class="son"></div>
    </div>
    <script>
        /*
        ### 阻止事件冒泡
            因为默认事件就处于冒泡阶段所以容易导致事件影响到父级
            如果需要事件就限制在当前元素内部，就需要阻止事件的冒泡 
                e.stopPropagation() // 阻止事件冒泡
         */
        document.addEventListener("click", function () {
            console.log("我是document（爷爷）");
        })
        document.querySelector(".father").addEventListener("click", function () {
            console.log("我是div类名为father（爸爸）");

        })
        document.querySelector(".son").addEventListener("click", function (e) {
            e.stopPropagation() // 阻止事件冒泡
            console.log("我是div类名为son（儿子）");

        }) 
    </script>
</body>

</html>